/*
 * @lc app=leetcode.cn id=306 lang=cpp
 *
 * [306] 累加数
 */

// @lc code=start
#include <bits/stdc++.h>
using namespace std;
class Solution
{
    // 如果num[i1, j1) + num[j1, j2) = num[j2, end)，则返回值为 end
    // 否则返回值为 -1
    int add(const string &num,
            const int i1,
            const int j1, const int j2)
    {
        if(j2 == num.size()) return -1;
        const int i2 = j1;
        const int len1 = j1 - i1;
        const int len2 = j2 - i2;
        
        int lstart = i1, lend = j1 - 1, rstart = i2, rend = j2 - 1;
        if(len1 < len2)
        {
            swap(lstart, rstart);
            swap(lend, rend);
        }

        // 保证 左边的数长度大于等于右边的
        char ans[64] = {0};
        memset(ans, 0, 64);
        int ians = 62;
        while(rend >= rstart)
        {
            ans[ians] += num[lend] + num[rend] - '0' * 2;
            if(ans[ians] > 9)
            {
                ans[ians - 1] += ans[ians] / 10;
                ans[ians] %= 10;
            }
            ians--;
            lend--;
            rend--;
        }
        while(lend >= lstart)
        {
            ans[ians] += num[lend] - '0';
            if(ans[ians] > 9)
            {
                ans[ians - 1] += ans[ians] / 10;
                ans[ians] %= 10;
            }
            ians--;
            lend--;
        }
        ians--;
        while(ans[ians] == 0 && ians < 64) ians++;//跳过前导0
        if(ians == 64)
        {
            //说明 ans = 0
            if(num[j2] == '0') return j2 + 1;
        }

        while(ians <= 62 && j2 < num.size())
        {
            if(ans[ians] + '0' != num[j2]) return -1;
            ians++;
            ++j2;
        }
        if(ians == 62) return j2;
        return -1;
    }

public:
    bool isAdditiveNumber(string num)
    {
        vector<pair<int, int>> dp[40][40];
        for(int i = 2; i < num.size(); i++)
        {
            for(int j = i + 1; j < num.size(); j++)
            {
                
            }
        }
    }
};
// @lc code=end
